<template>
        <el-card style="width:600px;">
            <div class="mem_tit">添加资讯</div>
            <div style="font-size: 20px;cursor:pointer" >
                <i @click="back" class="el-icon-back"></i>
            </div>
        <el-form title="添加资讯" :model="form" status-icon :rules="rules" ref="form" label-width="100px" class="demo-ruleForm">
            <el-form-item label="资讯标题" prop="title">
                <el-input type="text" v-model="form.title" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="资讯内容" prop="content">
                <el-input type="textarea" :rows="10" v-model="form.content" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('form')">提交</el-button>
                <el-button @click="resetForm('form')">重置</el-button>
            </el-form-item>
        </el-form>
    </el-card>

    
</template>

<script>
export default {
    name:'NewsAdd',
    data:function(){
        return{
            form:{
                title:'',
                content:''
            },
            rules:{
                title:[{required:true,message:'请填写资讯标题',trigger:'blur'}],
                content:[{required:true,message:'请填写资讯内容',trigger:'blur'}]
            }
        }
    },
    methods:{
        //返回分页展示页面
        back(){
            this.$router.back();
        },
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
            if (valid) {
                console.log(this);
               this.add(this.form.title,this.form.content);
            } else {
                console.log('error submit!!');
                return false;
            }
            });
      },
    resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      //修改资讯内容
    add(title,content){
        this.$axios({
            method:"post",
            url:'/easybuy/news/add',
            data:{
                title,
                content,
                isdel:0
            }
        }).then(rs=>{
            if(rs.data.code == 200){
                this.$message.success("添加成功!");
                this.$router.replace({path:'/back-index/back-news'});
            }else{
                this.$message.error("服务器错误!");
            }
        })
    }
    },
    
}
</script>

<style>

</style>